package chapter4.No4_1_使用reentrantLock类.demo13;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Created by Administrator on 2016/11/22.
 */
public class ServiceClass2 {
    ReentrantLock lock = new ReentrantLock();
    Condition condition = lock.newCondition();

    public void await() {
        lock.lock();
        try {
            condition.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        lock.unlock();
    }

    public void signal() {
        lock.lock();
        System.out.println("有没有线程在等待？"+lock.hasWaiters(condition)+" ，线程数是多少？"+
                    lock.getWaitQueueLength(condition));
        condition.signal();
        lock.unlock();
    }

}
